package me.luger.project.fof.controller.admin;

import me.luger.core.commom.util.StringUtil;
import me.luger.core.dao.nutz.entity.page.DataTableRequest;
import me.luger.core.mvc.controller.BaseController;
import me.luger.core.mvc.entity.Result;
import me.luger.core.mvc.interceptor.oplog.OpLog;
import me.luger.project.fof.service.FundInfoService;
import org.nutz.lang.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import me.luger.project.fof.service.FundInfoFilterConfigService;
import me.luger.project.fof.entity.FundInfoFilterConfig;

import java.util.List;

/**
 * FundInfoFilterConfig controller
 */
@Controller
@RequestMapping("/private/fof/fundInfoFilterConfig")
public class FundInfoFilterConfigController extends BaseController {

    private String viewBasePath = "/admin/modules/fundInfoFilterConfig/";

    @Autowired
    private FundInfoFilterConfigService fundInfoFilterConfigService;

    @Autowired
    private FundInfoService fundInfoService;

    @RequestMapping(value = "",name = "FundInfoFilterConfig列表页面")
    public ModelAndView index(){
        return btlView(viewBasePath + "index");
    }

    @RequestMapping(value = "data",name = "获取FundInfoFilterConfig列表")
    @ResponseBody
    public Object data(@RequestBody final DataTableRequest dataTableRequest){
        return fundInfoFilterConfigService.data(dataTableRequest);
    }



    @RequestMapping(value = "delete",name = "删除FundInfoFilterConfig接口")
    @ResponseBody
    public Object delete(String[] ids){
        fundInfoFilterConfigService.delete(ids);
        return Result.success("delete success");
    }

    @RequestMapping(value = "/detail/{id}",name = "获取FundInfoFilterConfig详细信息接口")
    public ModelAndView detail(@PathVariable("id") Integer id){
        FundInfoFilterConfig fundInfoFilterConfig = fundInfoFilterConfigService.fetchById(id);
        setAttr("fundInfoFilterConfig",fundInfoFilterConfig);
        return btlView(viewBasePath + "detail");
    }

    @RequestMapping(value = "add",name = "添加FundInfoFilterConfig页面")
    public ModelAndView add(){
        return btlView(viewBasePath + "add");
    }

    @RequestMapping(value = "addDo",name = "添加FundInfoFilterConfig接口")
    @ResponseBody
    @OpLog(name = "添加FundInfoFilterConfig",msg = "添加FundInfoFilterConfig")
    public Object adddo(FundInfoFilterConfig fundInfoFilterConfig){
        try{
            fundInfoFilterConfig = fundInfoFilterConfigService.insert(fundInfoFilterConfig);
        }catch (Exception e){
            return Result.error();
        }
        return Result.success();
    }

    @RequestMapping(value = "/edit/{id}",name = "更新FundInfoFilterConfig信息页面")
    public ModelAndView edit(@PathVariable Integer id){
        FundInfoFilterConfig fundInfoFilterConfig = fundInfoFilterConfigService.fetchById(id);
        setAttr("fundInfoFilterConfig",fundInfoFilterConfig);
        return btlView(viewBasePath + "edit");
    }

    @RequestMapping(value = "editDo",name = "更新FundInfoFilterConfig接口")
    @ResponseBody
    public Object editDo(FundInfoFilterConfig fundInfoFilterConfig){
        try{
            fundInfoFilterConfigService.updateIgnoreNull(fundInfoFilterConfig);
        }catch (Exception e){
            return Result.error();
        }

        String updateNow = getPara("updateNow");
        if(StringUtil.isNotBlank(updateNow)){
            fundInfoService.filterFundInfo(fundInfoFilterConfig);
        }
        return Result.success();
    }

    @RequestMapping(value = "doFundFilter",name = "根据管理平台条件进行基金过滤")
    @ResponseBody
    public Object doFundFilter(){
        FundInfoFilterConfig config = fundInfoFilterConfigService.fetchById(1L);
        int ret = fundInfoService.filterFundInfo(config);
        if(ret == 1){
            return Result.success();
        }else {
            return Result.error();
        }
    }
}
